package edu.hawaii.duedates;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;

/**
 * Tests the DueDates class methods. In order for the tests to pass, a user account must be created
 * in the ~duedates/duedates.xml. Set all values (name, email, password) to "test".
 * 
 * @author John
 * 
 */
public class TestDueDates {

  /** DueDates object to perform operations on. */
  private final DueDates duedates = new DueDates();
  
  private static final String test = "test";

  /**
   * Sets up DueDates with a dummy account.
   * 
   * @throws Exception If error finding account.
   */
  @Before
  public void setUp() throws Exception {
    String[] args = { test, test };
    duedates.findUser(args);
  }

  /**
   * Checks to see if user account has correct fields.
   * 
   * @throws Exception If user is not defined.
   */
  @Test
  public void testGetUser() throws Exception {
    assertEquals("Test findUser name", test, duedates.getUser().getName());
    assertEquals("Test findUser email", test, duedates.getUser().getEmail());
    assertEquals("Test findUser password", test, duedates.getUser().getPassword());
  }

  /**
   * Checks to see if results are printed properly.
   */
  @Test
  public void testPrintResults() {
    duedates.sortBy("date");
    duedates.sortBy("library");
    assertTrue("Test printResults", duedates.printResults().contains("No Items Due"));
    assertTrue("List should be empty", duedates.getItemList().isEmpty());
  }

  /**
   * Checks to see if the setFilter methods work.
   */
  @Test
  public void setFilters() {
    duedates.setLibraryFilterNone();
    assertFalse("Test uhmFilter", duedates.uhmFilter);
    assertFalse("Test hslFilter", duedates.hslFilter);
    duedates.setLibraryFilterOutHsl();
    assertFalse("Test uhmFilter", duedates.uhmFilter);
    assertTrue("Test hslFilter", duedates.hslFilter);
    duedates.setLibraryFilterOutUhm();
    assertTrue("Test uhmFilter", duedates.uhmFilter);
    assertFalse("Test hslFilter", duedates.hslFilter);
  }

}
